package controllers

import (
	"github.com/astaxie/beego"
)

type UserController struct {
	beego.Controller
}

func (c *UserController) Get() {
	//1、查询一条数据
	// user := models.User{Username: "lisi"}
	// models.DB.Find(&user)

	//2、查询所有数据
	/*user := []models.User{}
	models.DB.Find(&user)
	c.Data["json"] = user
	c.ServeJSON()*/

}

func (c *UserController) Add() {
	// c.Ctx.WriteString("增加数据")

	/*user := models.User{
		Username: "哈哈111",
		Age:      26,
		Email:    "hahha.qq.com",
		AddTime:  int(time.Now().Unix()),
	}
	models.DB.Create(&user)
	c.Ctx.WriteString("增加数据成功")*/
}

func (c *UserController) Edit() {

	//1、查找id=5的数据
	/*user := models.User{Id: 5}
	models.DB.First(&user)

	//2、执行修改
	user.Username = "王五"
	models.DB.Save(&user)

	c.Ctx.WriteString("修改数据成功")*/
}

func (c *UserController) Delete() {

	/*user := models.User{Id: 4}
	models.DB.Delete(&user)

	c.Ctx.WriteString("删除数据成功")*/
}
